$(document).ready(function () {
    initTable();
    $('#btnUpdate').bind('click',btnUpdateClick);
})


function btnUpdateClick() {
    /***
     *  bootstrapTable
     * 1. {} 传递参数
     * 2‘'  执行方法
    * */
    var row  = $('#list').bootstrapTable('getSelections')[0];
    $('#empName').val(row.name);

    $('#info').modal();
}


function initTable() {

    $('#list').bootstrapTable({
        url: 'http://test.org/employees',
        columns: columns,
        toolbar:'#toolbar',
        classes: ["table", "table-bordered", "table-striped"],
        singleSelect: true,
        clickToSelect: true,
        pagination: true,
        pageSize:3
    })
}

var columns = [
    {
        checkbox: true
    }, {
        field: 'name',
        title: '姓名'
    }, {
        field: 'dept',
        title: '部门',
        formatter: function (val, row, index) {

            var html = '';
            if (val == 'hr') {
                html = '人事部';
            }

            if (val == 'hr') {
                html = '人事部';
            }
            if (val == 'fin') {
                html = '财务部';
            }
            return html;
        }
    }, {
        field: 'gender',
        title: '性别'
    },{
        field:'id',
        title:"操作",
        formatter:function (val,row,index) {

            var box = $('<div></div>');
            var btnUpdate = $('<button></button>')
                .text("修改").addClass('btn').addClass('btn-warning');

            box.append(btnUpdate);

            var btnRemove = $('<button></button>')
                .text("删除").addClass('btn').addClass('btn-danger');

            box.append(btnUpdate);
            box.append(btnRemove);

            return box.html();
        }

    }]